
<div id="page-body" class="agency-detail clearfix">
    <div class="details block clearfix">
        <h2><?php echo $franchise->name ?></h2>
        <?php echo $franchise->location_addr_street1 ?><br>

        <?php echo $franchise->location_addr_suburb . ' ' . $franchise->location_addr_state . ' ' . $franchise->location_addr_pcode ?><br>		
        <strong>Phone:</strong> <?php echo $franchise->phone ?><br /> 
        <strong>Fax:</strong> <?php echo $franchise->fax ?>	<br /> 
    </div>

    <div class="clearer"></div>
    <div id="map_canvas" style="width:310px; height:200px; margin: 5px 10px 0px 0px;"></div>
    <script>
        var map;
        var lat;
        var lng;
        var mapOptions;
        var geocoder;
        var address;
        var myLatlng;

        geocoder = new google.maps.Geocoder();
        geocoder.geocode({'address': '<?php echo $franchise->location_addr_street1 . ' ' . $franchise->location_addr_suburb . ' ' . $franchise->location_addr_state . ' ' . $franchise->location_addr_pcode ?>'}, function(results, status) {
            if (status==google.maps.GeocoderStatus.OK) {
                //lng = results[0].geometry.location.lng();
                //lat = results[0].geometry.location.lat();
                //myLatlng = new google.maps.LatLng(lat,lng);
                myLatlng = results[0].geometry.location;

                mapOptions = {
                    center: myLatlng,
                    zoom: 15,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
                var marker = new google.maps.Marker({
                    position: myLatlng,
                    title:address
                });
                marker.setMap(map);
            }
            else {
                alert('Address not found');
            }
        });
    </script>
    <div class="clearer"></div>

    <div class="buttons">
        <a id="emailoffice-form-trigger" class="link-button agency-enquire" href="#">Email office</a>
    </div>
    <div class="clearer"></div>
    <div id="emailoffice-form" style="display:none;" class="clearfix form-togge" enquire-target="">
        <div class="form-divider"></div>
        <div id="emailoffice-form-content">
            <div id="form-error-msg"></div>
            <form id="email_office" class="cform appraisalrequest " method="post" capcharequest="" action="" enctype="multipart/form-data" name="agency-appraisal-form" onsubmit="">
                <div class="showError"></div>
                <div class="showSuccess"></div>
                <ol class="cf-ol">
                    <li class=""><label for="name"><span>Your Name * </span></label><input id="emailoffice_name" name="emailoffice_name" type="text" value=""/><span class="reqtxt"></span></li>
                    <li class=""><label for="emailAddress"><span>Email * </span></label><input id="emailoffice_email"  name="emailoffice_email" type="text" value=""/><span class="emailreqtxt"></span></li>

                    <li class=""><label for="mobile"><span>Mobile </span></label><input id="emailoffice_mobile"  name="emailoffice_mobile" type="text" value=""/></li>

                    <li class="" ><label for="message"><span>Message </span></label><textarea id="emailoffice_message"  name="emailoffice_message" style="resize: none"></textarea></li>
                </ol>
                <p class="cf-sb"><input type="submit" value="Submit" class="sendbutton" id="sendbutton3" name="sendbutton3"></p>		
            </form>
        </div>
        <a id="emailoffice-cancel" class="form-cancel" href="#">CANCEL</a>
    </div>

    <div class="buttons">
        <a id="marketappraisal-form-trigger" class="link-button agency-enquire" href="#">Free Market Appraisal</a>
    </div>
    <div class="clearer"></div>
    <div id="marketappraisal-form" style="display:none;" class="clearfix form-togge" enquire-target="">
        <div class="form-divider"></div>
        <div id="marketappraisal-form-content">
            <div id="form-error-msg"></div>
            <form id="marketappraisal_office" class="cform appraisalrequest " method="post" capcharequest="" action="" enctype="multipart/form-data" name="agency-appraisal-form" onsubmit="">
                <div class="showError"></div>
                <div class="showSuccess"></div>
                <ol class="cf-ol">
                    <li class="textonly">
                        <h2 class="gogecko-orange">Your Details</h2>
                    </li>
                    <li class=""><label for="marketappraisal_name"><span>Your Name * </span></label><input id="marketappraisal_name" name="marketappraisal_name" type="text" value=""/><span class="reqtxt"></span></li>
                    <li class=""><label for="marketappraisal_email"><span>Email * </span></label><input id="marketappraisal_email"  name="marketappraisal_email" type="text" value=""/><span class="emailreqtxt"></span></li>
                    <li class=""><label for="marketappraisal_mobile"><span>Mobile </span></label><input id="marketappraisal_mobile"  name="marketappraisal_mobile" type="text" value=""/></li>
                    <li class=""><label for="marketappraisal_address"><span>Address </span></label><input id="marketappraisal_address"  name="marketappraisal_address" type="text" value=""/></li>
                    <li class="textonly">
                        <h2 class="gogecko-orange">Property Address</h2>
                    </li>
                    <li class="">
                        <label for="marketappraisal_type"><span>Appraisal type </span></label><br>
                        <input type="radio" name="marketappraisal_type" id="marketappraisal_type_forsale" checked value="sale"/><label for="marketappraisal_type_forsale" style="padding:0 4px">For Sale</label>
                        <input type="radio" name="marketappraisal_type" id="marketappraisal_type_forrent" value="rent"/><label for="marketappraisal_type_forrent" style="padding:0 4px">For Rent</label>
                    </li>
                    <li class="">
                        <label for="marketappraisal_propertytype"><span>Property type </span></label>
                        <select name="marketappraisal_propertytype" class="last">
                            <option value=""></option>
                            <option value="acreagesemirural">Acreage/Semi Rural</option>
                            <option value="apartment">Apartment</option>
                            <option value="blockofunits">Block of Units</option>
                            <option value="colonial">Colonial</option>
                            <option value="development">Development</option>
                            <option value="duplex">Duplex</option>
                            <option value="federation">Federation</option>
                            <option value="homeandoffice">Home &amp; Office</option>
                            <option value="house">House</option>
                            <option value="houseandland">House &amp; Land Package</option>
                            <option value="investment">Investment</option>
                            <option value="project">Project</option>
                            <option value="queenslander">Queenslander</option>
                            <option value="townhouse">Townhouse</option>
                            <option value="unit">Unit</option>
                            <option value="vacantland">Vacant Land</option>
                            <option value="villa">Villa</option>
                            <option value="waterfrontbeach">Waterfront Beach</option>
                            <option value="waterfrontcanal">Waterfront Canal</option>
                        </select>
                    </li>

                    <li class="" >
                        <label for="marketappraisal_propertyage"><span>Age of property </span></label>
                        <input id="marketappraisal_propertyage"  name="marketappraisal_propertyage" type="text" value="" />
                    </li>
                    <li class="">
                        <label for="marketappraisal_bedrooms"><span>Bedrooms </span></label>
                        <select name="marketappraisal_bedrooms" class="last">
                            <option value=""></option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                            <option value="7">7</option>
                            <option value="8">8</option>
                            <option value="9">9</option>
                            <option value="10">10</option>
                        </select>
                    </li>
                    <li class="">
                        <label for="marketappraisal_bedrooms"><span>Bathrooms </span></label>
                        <select name="marketappraisal_bathrooms" class="last" >
                            <option value=""></option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                            <option value="7">7</option>
                            <option value="8">8</option>
                            <option value="9">9</option>
                            <option value="10">10</option>
                        </select>
                    </li>
                    <li class=""><label for="marketappraisal_landarea"><span>Land area </span></label><input id="marketappraisal_landarea"  name="marketappraisal_landarea" type="text" value="" /></li>
                    <li class=""><label for="marketappraisal_landarea"><span>Additional info </span></label><textarea id="marketappraisal_additionalinfo"  name="marketappraisal_additionalinfo" style="resize: none"></textarea></li>
                    <li class=""><label for="marketappraisal_landarea"><span>Comments </span></label><textarea id="marketappraisal_comments"  name="marketappraisal_comments" style="resize: none"></textarea></li>
                </ol>
                <p class="cf-sb"><input type="submit" value="Submit" class="sendbutton" id="sendbutton3" name="sendbutton3"></p>		
            </form>
        </div>
        <a id="marketappraisal-cancel" class="form-cancel" href="#">CANCEL</a>

    </div>

    <script type="text/javascript">
        (function($) {
            // Form dropdown button
            $(function() {
                var content = $("#emailoffice-form");
                var trigger = $("#emailoffice-form-trigger");
                var cancel = $("#emailoffice-cancel")
                var mcontent = $("#marketappraisal-form");
                var mtrigger = $("#marketappraisal-form-trigger");
                var mcancel = $("#marketappraisal-cancel")
                

                trigger.click(function(e) {
                    e.preventDefault();
                    if (content.is(":visible")) {
                        content.slideUp(500);
                        trigger.removeClass('active');
                    } else {
                        content.slideDown(500);
                        trigger.addClass('active');
                    }
                });
                cancel.click(function(e) {
                    e.preventDefault();
                    if (content.is(":visible")) {
                        content.slideUp(500);
                        trigger.removeClass('active');
                    }
                });
                mtrigger.click(function(e) {
                    e.preventDefault();
                    if (mcontent.is(":visible")) {
                        mcontent.slideUp(500);
                        mtrigger.removeClass('active');
                    } else {
                        mcontent.slideDown(500);
                        mtrigger.addClass('active');
                    }
                });
                mcancel.click(function(e) {
                    e.preventDefault();
                    if (mcontent.is(":visible")) {
                        mcontent.slideUp(500);
                        mtrigger.removeClass('active');
                    }
                });

            });

        })(jQuery);
        
        $(document).ready(function(){
            $('form#marketappraisal_office').submit(function() {
                var e = $(this);
                $('#marketappraisal_office .showError').html('');
                $('#marketappraisal_office .showSuccess').html('');
                $('#marketappraisal_office .error').removeAttr('class','error');
                var form_data = $('#marketappraisal_office').serialize();
                //Begin the ajax call
                $.ajax({
                    url: "<?php echo site_url('offices/marketappraisal_email/' . $franchise->id) ?>",
                    type: "POST",
                    data: form_data,
                    dataType: "json",
                    cache: false,
                    success: function(json) {
                        var usermessage = json.usermessage;
                        var fielderrors = json.fielderrors;
                        
                        if (usermessage[0] == 'error')
                        {
                            //Show the user the errors.
                            $('#marketappraisal_office .showError').html(usermessage[1]);
                            if(usermessage[2] == 1){
                                $('#marketappraisal_office .showError').html(usermessage[1]);
                            }else{
                                $(' #marketappraisal_office .showError').show();
                                $.each(fielderrors, function(id, value) {
                                    $('#'+id).addClass('error');
                                    $('#'+id).focus();
                                });
                                
                            }
                                
                        } else {
                            $('#marketappraisal_office')[0].reset();
                            $('#marketappraisal_office .showError').html('');
                            $('#marketappraisal_office .showSuccess').html(usermessage[1]);
                            $('#marketappraisal-form-trigger').focus();
                        }
                    }
                });
                return false;
            });
            
            $('form#email_office').submit(function() {
                $('#email_office .showError').html('');
                $('#email_office .showSuccess').html('');
                $('#email_office .error').removeAttr('class','error');
                var e = $(this);
                var form_data = $('#email_office').serialize();
                //Begin the ajax call
                $.ajax({
                    url: "<?php echo site_url('offices/office_email/' . $franchise->id) ?>",
                    type: "POST",
                    data: form_data,
                    dataType: "json",
                    cache: false,
                    success: function(json) {
                        var usermessage = json.usermessage;
                        var fielderrors = json.fielderrors;
                        
                        if (usermessage[0] == 'error')
                        {
                            //Show the user the errors.
                            $('#email_office .showError').html(usermessage[1]);
                            if(usermessage[2] == 1){
                                $('#email_office .showError').html(usermessage[1]);
                            }else{
                                $(' #email_office .showError').show();
                                var i = 0;
                                $.each(fielderrors, function(id, value) {
                                    
                                    $('#'+id).addClass('error');
                                    if(i==0)
                                        $('#'+id).focus();
                                    i++
                                });
                            }
                                
                        } else {
                            $('#email_office')[0].reset();
                            $('#email_office .showError').html('');
                            $('#email_office .showSuccess').html(usermessage[1]);
                            $('#emailoffice-form-trigger').focus();
                        }
                    }
                });
                return false;
            });
        })
        
        function get_office(id,type,start,status){
            $.ajax({
                url: "<?php echo site_url('offices/get_office') ?>/"+type+'/'+start+'/<?php echo $franchise->id ?>',
                dataType: "HTML",
                cache: false,
                success: function(data) {
                    if(data){
                        $('#'+id).html(data);
                        $('#'+id).attr('rel',start);
                    }else if (start == 0){
                        $('#'+id).html('');
                    }
                        
                }
            });
        }
        
        function nextrecord(id,type){
            var start = $('#'+id).attr('rel');
            start = parseInt(start)+1;
            get_office(id,type,start);
            
        }
        function backrecord(id,type){
            var start = $('#'+id).attr('rel');
            start = parseInt(start);
            if(start > 0){
                start = start -1;
                get_office(id,type,start);
               
            }
        }
        
        function changeStatus(status){
            $('#ofice_status').attr('rel',0);
            $('#ofice_status').attr('status',status);
            $('.status').removeClass('active');
            $('#'+status).addClass('active')
            get_office('ofice_status',status,0);
        }
        
        function backoffice(){
            var start = $('#ofice_status').attr('rel');
            var type = $('#ofice_status').attr('status');
            start = parseInt(start);
            if(start > 0){
                start = start -1;
                get_office('ofice_status',type,start);
               
            }
        }
        
        function nextoffice(id,type){
            var start = $('#ofice_status').attr('rel');
            var type = $('#ofice_status').attr('status');
            start = parseInt(start)+1;
            get_office('ofice_status',type,start);
            
        }
        $(document).ready(function(){
            get_office('last_list','listings',0);
            get_office('ofice_status','sold',0);
        })
    </script>
    <?php if (!empty($franchise->quote)) { ?>
        <div class="agency-descrip block">
            <?php echo $franchise->quote; ?>
        </div>
    <?php } ?>

    <div class="contentright">
        <table>
            <tr>
                <td>
                    <h2 class="latest-listing"><a href="javascript:get_office('last_list','listings',0)">Latest Listings</a></h2> 
                </td>
            </tr>
            <tr>
                <td>
                    <div id="last_list" style="padding: 10px;" rel="0"></div>
                </td>
            </tr>
            <tr>
                <td style="height:30px">
                    <a href="javascript:backrecord('last_list','listings')"><img src="<?php echo base_url(); ?>img/arrow-top.png" alt="" style="margin-top: 10px" /></a>
                </td>
            </tr>
            <tr>
                <td style="height:30px">
                    <a href="javascript:nextrecord('last_list','listings')"><img src="<?php echo base_url(); ?>img/arrow-bottom.png" alt="" style="margin-top: 10px" /></a>
                </td>
            </tr>
        </table>
        <table>
            <tr>
                <td>
                    <h2><a href="javascript:changeStatus('sold')" class="status active" id="sold">For Sale</a></h2>
                </td>
            </tr>
            <tr>
                <td>
                    <h2><a href="javascript:changeStatus('rentals')" class="status" id="rentals">For Rent</a></h2>
                </td>
            </tr>
            <tr>
                <td>
                    <h2><a href="javascript:changeStatus('leased')" class="status" id="leased">Sold</a></h2> 
                </td>
            </tr>
            <tr>
                <td>
                    <div id="ofice_status" style="padding: 10px;" rel="0" status="sold"></div>
                </td>
            </tr>
            <tr>
                <td style="height:30px">
                    <a href="javascript:backoffice()"><img src="<?php echo base_url(); ?>img/arrow-top.png" alt="" style="margin-top: 10px" /></a>
                </td>
            </tr>
            <tr>
                <td style="height:30px">
                    <a href="javascript:nextoffice()"><img src="<?php echo base_url(); ?>img/arrow-bottom.png" alt="" style="margin-top: 10px" /></a>
                </td>
            </tr>
        </table>
        <table>
            <tr>
                <td>
                    <h2><?php echo anchor('offices/team/' . $franchise->id, 'Meet The Team'); ?></h2>
                </td>
            </tr>
            <tr>
                <td>
                    <h2><?php echo anchor('offices/testimonial/' . $franchise->id, 'Testimonials', array('class' => 'active')); ?></h2>
                </td>
            </tr>
            <tr>
                <td>
                    <div style="padding: 10px;">
                        <p>Words cannot express how thankful I am for your dedication under
                            at times difficult circumstances. The sale of this house has given
                            me closure and is allowing us all to move forward. Thank you again
                            for your wonderful service and professional manner.</p> 
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <p style="padding:0; line-height: 8px; margin:8px 0">
                        <a href="<?php echo site_url('offices/testimonial/' . $franchise->id) ?>" class="view-all">View All</a>
                    </p>
                </td>
            </tr>
        </table>
        <div class="clearer"></div>
    </div>
    <div class="clearer"></div>
</div>
